package boun.center;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class CMPENewsAdapter extends BaseAdapter {
	private Context context;
	private static ArrayList<CmpeNews> news;
	
	public CMPENewsAdapter(Context c) throws IOException, ParseException{
		context = c;
		news = CmpeNewsFetcher.fetchCmpeNews();
	}
	
	@Override
	public int getCount() {
		
		return news.size();
	}

	@Override
	public Object getItem(int position) {
		return news.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if(convertView == null){
			LayoutInflater inflater	= LayoutInflater.from(context);
			convertView = inflater.inflate(R.layout.calendar_list_item,parent,false);
		}
		String date = (new SimpleDateFormat("dd/MM/yy")).format(news.get(position).getCreationDate().getTime());
		TextView Date = (TextView) convertView.findViewById(R.id.event_date);
		Date.setText(date);
		TextView EventName = (TextView) convertView.findViewById(R.id.event_name);
		EventName.setText(news.get(position).getSubject());
		return convertView;
	}

}
